package model.action;

import java.util.List;
import datacontainer.ImmuTable;


/**
 * Abstract class for all action objects.
 * All action objects have common behavior of being passed
 * references to data objects from the Model.
 * 
 * @author Michael Deng
 * @author Jei Min Yoo
 * 
 */
public abstract class AbstractAction {

    /**
     * This method sets up inputs for actions.
     * @param column column of interest
     * @param conditions list of conditions
     */
    public abstract void setInput (String column, List<String> conditions);

    /**
     * This method executes the action of the action object.
     * @param workSpace reference to the workspace
     * @param rawData reference to the raw data
     */
    public abstract void execute (ImmuTable workSpace, ImmuTable rawData);

    /**
     * This method returns the index of the columnName in the
     * header list of the rawdata store. If the columnName
     * does not exist in the header list, then this will return -1.
     * 
     * @param columnName
     * @return
     */
    protected int getWorkSpaceColumnIndex (ImmuTable workSpace, String columnName) {
        return workSpace.getHeaders().indexOf(columnName);
    }

    /**
     * This method returns the index of the columnName in the
     * header list of the rawdata store. If the columnName
     * does not exist in the header list, then this will return -1.
     * 
     * @param columnName
     * @return
     */
    protected int getRawDataColumnIndex (ImmuTable raw, String columnName) {
        return raw.getHeaders().indexOf(columnName);
    }

    /**
     * This method removes the single row specified by the index
     * from the data table.
     * 
     * @param index
     */
    protected void removeRow (ImmuTable workSpace, int index) {
        for (List<String> rowCell : workSpace.getData()) {
            rowCell.remove(index);
        }
    }
}
